import typeToReducer from 'type-to-reducer'
import {
  POST_ORDER_SUBMIT,
  POST_PRICE_EXTRACT
} from './../constants/actionTypes'

const initialState = {
  data: null,
  isLoading: false,
  error: false
}


//订单提交
export const orderSubmitReducer = typeToReducer({
  [POST_ORDER_SUBMIT]: {
    LOADING: () => ({
      ...initialState,
      isLoading: true,
    }),
    SUCCESS: (state, action) => {
      return {
        ...initialState,
        data: action.payload.data,
      }
    },
    ERROR: (state, action) => ({
      ...initialState,
      error: action.payload
    })
  }
}, initialState)



//积分提现
export const priceExtractReducer = typeToReducer({
  [POST_PRICE_EXTRACT]: {
    LOADING: () => ({
      ...initialState,
      isLoading: true,
    }),
    SUCCESS: (state, action) => {
      return {
        ...initialState,
        data: action.payload.data,
      }
    },
    ERROR: (state, action) => ({
      ...initialState,
      error: action.payload
    })
  }
}, initialState)